package com.ag.lzm.action;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.ag.bean.TbPlan;
import com.ag.bean.TbPlanStandard;
import com.ag.common.AjaxNotify;
import com.ag.common.BaseAction;
import com.ag.lzm.service.IPlanService;

public class SavePlanAction extends BaseAction implements SessionAware {
	private static final long serialVersionUID = -3203598068028956829L;
	private TbPlan plan;
	private String ajaxRst;
	private String plankeywords;
	private Map<String, Object> session;
	private String PId;
	private String planStatus;
	private String POpinion;

	// 预案标准字段
	private TbPlanStandard planStandard;

	public TbPlanStandard getPlanStandard() {
		return planStandard;
	}

	public void setPlanStandard(TbPlanStandard planStandard) {
		this.planStandard = planStandard;
	}

	/**
	 * 预案步骤JSON字符串
	 */
	private String planSteps;

	/**
	 * 预案ID
	 */
	private String planID;

	public void setPlanID(String planID) {
		this.planID = planID;
	}

	public void setPlanSteps(String planSteps) {
		this.planSteps = planSteps;
	}

	/**
	 * 预案业务对象
	 */
	private IPlanService planService;

	/**
	 * 审批预案
	 * 
	 * @return
	 */
	public String auditPlan() {
		try {
			planService.auditPlan(PId, planStatus, POpinion);
			ajaxRst = AjaxNotify.SUCCESS;
			return "operate";
		} catch (Exception e) {
			e.printStackTrace();
			ajaxRst = AjaxNotify.EXCEPTION;
			return "operate";
		}
	}

	/**
	 * 保存预案步骤
	 * 
	 * @return
	 */
	public String savePlanSteps() {
		try {
			planService.savePlanSteps(planID, planSteps);
			ajaxRst = AjaxNotify.SUCCESS;
			return "operate";
		} catch (Exception e) {
			e.printStackTrace();
			ajaxRst = AjaxNotify.EXCEPTION;
			return "operate";
		}
	}

	/**
	 * 保存预案启动标准
	 * 
	 * @return
	 */
	public String savePlanStandard() {
		try {
			// planService.savePlanSteps(planID,planSteps);
			planService.savePlanStandard(planStandard);
			ajaxRst = AjaxNotify.SUCCESS;
			return "operate";
		} catch (Exception e) {
			e.printStackTrace();
			ajaxRst = AjaxNotify.EXCEPTION;
			return "operate";
		}
	}

	/**
	 * 保存预案
	 * 
	 * @return
	 */
	public String savePlan() {
		try {
			// List<PlanAnnex> paList=(List<PlanAnnex>)
			// session.get(PlanUtils.PLAN_ANNEX);
			// for (PlanAnnex planAnnex : paList) {
			// System.out.println("planAnnex.getPaId()"+planAnnex.getPaId());
			// System.out.println("planAnnex.getPaName()"+planAnnex.getPaName());
			// }
			PId = planService.savePlan(plan, plankeywords, session);
			ajaxRst = AjaxNotify.SUCCESS;
			return "save_plan_succ";
		} catch (Exception e) {
			e.printStackTrace();
			ajaxRst = AjaxNotify.EXCEPTION;
			return "save_plan_fail";
		}
	}

	@Override
	public void setSession(Map<String, Object> sessionMap) {
		this.session = sessionMap;

	}

	public void setPlanService(IPlanService planService) {
		this.planService = planService;
	}

	public TbPlan getPlan() {
		return plan;
	}

	public void setPlan(TbPlan plan) {
		this.plan = plan;
	}

	public void setPlankeywords(String plankeywords) {
		this.plankeywords = plankeywords;
	}

	public String getAjaxRst() {
		return ajaxRst;
	}

	public void setPOpinion(String opinion) {
		POpinion = opinion;
	}

	public void setPlanStatus(String planStatus) {
		this.planStatus = planStatus;
	}

	public void setPId(String id) {
		PId = id;
	}

	public String getPId() {
		return PId;
	}

}
